package top.codecrab.eblog.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author 王刚
 * @since 2022年03月18日 20:49
 */
@Controller
public class CategoryController extends BaseController {

    @GetMapping("/category/{id:\\d*}")
    public String category(@PathVariable("id") Long id, Boolean recommend) {
        int cp = ServletRequestUtils.getIntParameter(request, "cp", 1);
        request.setAttribute("currentCategoryId", id);
        request.setAttribute("cp", cp);
        request.setAttribute("isRecommend", recommend);
        request.setAttribute("isOrder", "created");
        return "post/category";
    }

    @GetMapping("/category/recommend")
    public String recommend(Long id, Boolean recommend, String order) {
        int cp = ServletRequestUtils.getIntParameter(request, "cp", 1);
        request.setAttribute("currentCategoryId", id);
        request.setAttribute("cp", cp);
        request.setAttribute("isRecommend", recommend);
        request.setAttribute("isOrder", order);
        return "post/category";
    }

}
